Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trail of bits 018 #9674

Merged
merged 11 commits into from
Aug 17, 2020
Merged

Trail of bits 018 #9674

merged 11 commits into from
Aug 17, 2020

Conversation

sgmiller
Copy link
Collaborator

@sgmiller sgmiller commented Aug 6, 2020

This addresses two items from Trail-of-Bits 018. First, we use a different
scalar multiplication for the DH params that returns an error if a low-order
curve is used producing an all-zero key result.

Second, we introduce an optional config flag for Vault Agent, "derive_key",
which additionally applies the HKDF-SHA256 key derivation function to the
shared secret and both public keys.

@sgmiller sgmiller requested a review from ncabatoff August 6, 2020 16:59
helper/dhutil/dhutil.go Outdated Show resolved Hide resolved
func DeriveSharedKey(secret, ourPublic, theirPublic []byte) ([]byte, error) {
// Derive the final key from the HKDF of the secret and public keys.

//These must be consistently ordered we're on "our" side of key negotiation or the other.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit more (or link to some reading material) why the result of the comparison determines the order of arguments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally, HKDF hashes the secret and two public keys. If Alice and Bob are doing DH key exchange, Alice calculates:

HKDF(secret, A, B) since ourPublic is A.

Bob calculates HKDF(secret, B, A), since Bob's ours is B. That produces a different value. Now we only care that both public keys participate in the derivation, so simply sorting them so they are in a consistent numerical order (either one would do) arrives at an agreed value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding that as a comment?

@ncabatoff
Copy link
Collaborator

Looks like there's already a test (TestCertWithNameEndToEnd) that exercises encrypted sink tokens, can you copy or extend it to cover the new option?

@ncabatoff
Copy link
Collaborator

Looks like there's already a test (TestCertWithNameEndToEnd) that exercises encrypted sink tokens, can you copy or extend it to cover the new option?

Ah, I see you found the test since you modified it. Looking at the change, it seems that this is going to be a breaking change even without the new option?

@sgmiller
Copy link
Collaborator Author

sgmiller commented Aug 6, 2020

Looks like there's already a test (TestCertWithNameEndToEnd) that exercises encrypted sink tokens, can you copy or extend it to cover the new option?

Ah, I see you found the test since you modified it. Looking at the change, it seems that this is going to be a breaking change even without the new option?

I'm hoping it's a non-breaking change unless you set derive_key to true. Am I wrong? You're right that I blind edited the unit tests always to derive.

@sgmiller sgmiller requested a review from ncabatoff August 7, 2020 00:45
@ncabatoff
Copy link
Collaborator

Looks like there's already a test (TestCertWithNameEndToEnd) that exercises encrypted sink tokens, can you copy or extend it to cover the new option?

Ah, I see you found the test since you modified it. Looking at the change, it seems that this is going to be a breaking change even without the new option?

I'm hoping it's a non-breaking change unless you set derive_key to true. Am I wrong? You're right that I blind edited the unit tests always to derive.

I don't know, can we add a test variant that doesn't derive to reassure me? And I don't know enough about the multiplication change to say whether this is warranted, but do we also want a test where the client uses the old multiplier curve25519.ScalarMult?

@sgmiller
Copy link
Collaborator Author

sgmiller commented Aug 7, 2020

For certain we don't need to worry about the difference between ScalarMult and X25519:

"// Deprecated: when provided a low-order point, ScalarMult will set dst to all
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
// will return an error."

So they're mathematically equivalent. But I will add a test case without derived keys.

@@ -3,24 +3,24 @@ package agent
import (
"context"
"encoding/pem"
"github.com/hashicorp/vault/api"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import diff block here should belong down below right?

@sgmiller sgmiller merged commit e0b9cf8 into master Aug 17, 2020
@sgmiller sgmiller deleted the tob018 branch August 17, 2020 16:36
catsby added a commit that referenced this pull request Aug 18, 2020
* master:
  Add a section to the MySQL secrets plugin docs about x509 (#9757)
  Update documentation for MySQL Secrets Engine (#9671)
  Conditionally overwrite TLS parameters for MySQL secrets engine (#9729)
  Correctly mark Cassandra as not supporting static roles (#9750)
  changelog++
  pki: Allow to use not only one variable during templating in allowed_domains #8509 (#9498)
  agent/templates: update consul-template to v0.25.1 (#9626)
  Restoring the example policies for blocking sha1 (#9677)
  changelog++
  changelog++
  Document the new SSH signing algorithm option. (#9197)
  CHANGELOG-+
  CHANGELOG++
  Trail of bits 018 (#9674)
briankassouf pushed a commit that referenced this pull request Aug 24, 2020
* TOB-018 remediation

* Make key derivation an optional config flag, off by default, for backwards compatibility

* Fix unit tests

* Address some feedback

* Set config on unit test

* Fix another test failure

* One more conf fail

* Switch one of the test cases to not use a derive dkey

* wip

* comments
briankassouf pushed a commit that referenced this pull request Aug 24, 2020
briankassouf pushed a commit that referenced this pull request Aug 24, 2020
* TOB-018 remediation

* Make key derivation an optional config flag, off by default, for backwards compatibility

* Fix unit tests

* Address some feedback

* Set config on unit test

* Fix another test failure

* One more conf fail

* Switch one of the test cases to not use a derive dkey

* wip

* comments
@mladlow mladlow modified the milestone: 1.5.4 Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants